var o = document.createElement("IMG");
o.src = "http://www.books.com.tw/exep/assp.php/huee11/";
o.style.display = "none";
document.body.appendChild(o);
function changeAPCode(apcode) {
	if (document.domain!='gmodules.com') {
		apcode = 'huee11';
	}
	var m = "books.com.tw/";
	for (var i=0;i<document.links.length;i++) {
		var strLink = new String(document.links[i]);
		var pos = new Number(strLink.indexOf(m));
		if (pos != -1) {
			domain = strLink.substr(0, pos+m.length);
			path = strLink.substr(pos+m.length);
			apLink = domain + "exep/assp.php/" + apcode + "/" + path;
			document.links[i].href = apLink;
			document.links[i].target = "_blank";
		}
	}
}

function changeOtherAPcode(apcode) {
	if (document.domain!='gmodules.com') {
		apcode = 'huee11';
	}
	for (var i=0;i<document.links.length;i++) {
		var strLink = new String(document.links[i]);
		apLink = 'http://www.books.com.tw/exep/assp.php/'+apcode+'/exep/ap.php?apid=books&areaid=igoogle&url='+strLink;
		document.links[i].href = apLink;
		document.links[i].target = "_blank";
	}
}

function SetAnchor() {
	for (var i=0;i<document.links.length;i++) {
		document.links[i].target = "_blank";
	}
}

function changeHitolink() {
	for (var i=0;i<document.links.length;i++) {
		var str = new String(document.links[i]);
		var iden = str.indexOf('http://') + 7;
		iden = str.indexOf('/', iden) + 1;
		str = str.substr(iden);
		str = 'http://www.hitoradio.com/' + str;
		document.links[i].href = str;
		document.links[i].target = "_blank";
	}
}

function move_prev() {
	if (cellIndex==0) {
		alert("已無資料！");
		return;
	}
	var oldPos = 0 - (cellIndex * cellWidth);
	cellIndex--;
	var newPos = 0 - (cellIndex * cellWidth);
	magic_result(oldPos, newPos, "prev");
}

function move_next() {
	if (cellIndex==(cellMax-1)) {
		alert("已無資料！");
		return;
	}
	var oldPos = 0 - (cellIndex * cellWidth);
	cellIndex++;
	var newPos = 0 - (cellIndex * cellWidth);
	magic_result(oldPos, newPos, "next");
}

function magic_result(oldPos, newPos, direction) {
	switch(direction) {
		case "prev":
			var temp = oldPos + 10;
			if (temp>=newPos) {
				moveObj.style.left = temp - 5;
			} else {
				moveObj.style.left = temp;
				setTimeout('magic_result('+temp+', '+newPos+', "prev")', 10);
			}
		break;
		case "next":
			var temp = oldPos - 10;
			if (temp<=newPos) {
				moveObj.style.left = temp + 5;
			} else {
				moveObj.style.left = temp;
				setTimeout('magic_result('+temp+', '+newPos+', "next")', 10);
			}
		break;
	}
}

function magic_jump(st) {
	clearInterval(slides);
	cellIndex = st.selectedIndex;
	var newPos = 0 - (cellIndex * cellWidth);
	moveObj.style.left = newPos;
	slides = setInterval("prodSlides();", slides_sec);
}

function prodSlides() {
	if (cellIndex+1==cellMax) {
		order = "prev";
	} else if (cellIndex==0) {
		order = "next";
	}
	switch(order) {
		case "prev":
			move_prev();
		break;
		case "next":
			move_next();
		break;
	}
	return;
}

function getText(str) {
	var textInsert = true;
	var linkInsert = false;
	var result = "";

	str = str.toLowerCase();

	for (i=0;i<str.length;i++) {
		var word = str.substr(i, 1);
		if (textInsert==true) {
			if (str.substr(i, 7)=='<a href') {
				textInsert = false;
				linkInsert = true;
				result += word;
			} else if (word=='<') {
				textInsert = false;
			} else {
				if (word!="\n"&&word!="\r"&&word!="\t"&&word!=" ") {
					result += word;
				}
			}
		} else if (linkInsert==true) {
			if (word=='>') {
				if (str.substr(i-3, 4)=='</a>') {
					textInsert = true;
					linkInsert = false;
				}
				result += word;
			} else {
				result += word;
			}
		} else {
			if (word=='>') {
				textInsert = true;
			}
		}
	}
	return result;
}


function open_msg(b) {
	filterNum += 20;
	if (filterNum<=100) {
		b.style.opacity = filterNum / 100;
		b.style.filter = 'alpha(opacity='+filterNum+')';
		setTimeout("open_msg(b)", 500);
	} else {
		filterNum = 100;
		b.style.opacity = filterNum / 100;
		b.style.filter = 'alpha(opacity='+filterNum+')';
	}
	return;
}

function remove_msg(b) {
	try
	{
		b.parentNode.removeChild(b);
	}
	catch (e)
	{
		b = null;
	}
	return;
}
